using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class TF_Country {
		#region Fields
		private int id;
		private int countryID;
		private string countryName;
		private string description;
		private int languageId;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the TF_Country class.
		/// </summary>
		public TF_Country() {
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_Country class.
		/// </summary>
		public TF_Country(int countryID, string countryName, string description, int languageId) {
			this.countryID = countryID;
			this.countryName = countryName;
			this.description = description;
			this.languageId = languageId;
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_Country class.
		/// </summary>
		public TF_Country(int id, int countryID, string countryName, string description, int languageId) {
			this.id = id;
			this.countryID = countryID;
			this.countryName = countryName;
			this.description = description;
			this.languageId = languageId;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the CountryID value.
		/// </summary>
		public int CountryID {
			get { return countryID; }
			set { countryID = value; }
		}
		
		/// <summary>
		/// Gets or sets the CountryName value.
		/// </summary>
		public string CountryName {
			get { return countryName; }
			set { countryName = value; }
		}
		
		/// <summary>
		/// Gets or sets the Description value.
		/// </summary>
		public string Description {
			get { return description; }
			set { description = value; }
		}
		
		/// <summary>
		/// Gets or sets the LanguageId value.
		/// </summary>
		public int LanguageId {
			get { return languageId; }
			set { languageId = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the TF_Country table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("TF_CountryInsert", countryID, countryName, description, languageId));
		}
		
		/// <summary>
		/// Updates a record in the TF_Country table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("TF_CountryUpdate", id, countryID, countryName, description, languageId);
		}
		
		/// <summary>
		/// Deletes a record from the TF_Country table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("TF_CountryDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the TF_Country table.
		/// </summary>
		public static TF_Country Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_CountrySelect", id)) {
				if (dataReader.Read()) {
					return MakeTF_Country(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the TF_Country table.
		/// </summary>
		public static List<TF_Country> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_CountrySelectAll")) {
				List<TF_Country> tF_CountryList = new List<TF_Country>();
				while (dataReader.Read()) {
					TF_Country tF_Country = MakeTF_Country(dataReader);
					tF_CountryList.Add(tF_Country);
				}
				return tF_CountryList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the TF_Country class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TF_Country MakeTF_Country(SqlDataReader dataReader) {
			TF_Country tF_Country = new TF_Country();
			
			if (dataReader.IsDBNull(0) == false) {
				tF_Country.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tF_Country.CountryID = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tF_Country.CountryName = dataReader.GetString(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tF_Country.Description = dataReader.GetString(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tF_Country.LanguageId = dataReader.GetInt32(4);
			}

			return tF_Country;
		}
		#endregion
	}
}
